package com.mworld.galaxy.bull.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mworld.galaxy.bull.entity.product.Shop;
import com.mworld.galaxy.bull.service.product.ShopService;
import com.mworld.galaxy.bull.util.ShopUtil;

/**
 * 首页
 * 
 * URL : GET / <br>
 * 
 * @author michael
 */
@Controller
@RequestMapping(value = "/")
public class IndexController {

    @Autowired
    ShopService shopService;

    @RequestMapping(value = "")
    public String index(Model model, HttpServletRequest request) {
        String serverName = request.getServerName();
        if (serverName.equals("www.51qianlima.cn") || serverName.equals("51qianlima.cn")
                || serverName.equals("localhost") || serverName.equals("127.0.0.1")) {
            return "member/login";
        }
        String shopDomainNameOrId = ShopUtil.getShopNameOrId(request);
        Shop shop = ShopUtil.getShopByDomainNameOrId(shopService, shopDomainNameOrId);
        return shop == null ? "error/404" : "shop/home";
    }

}
